﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// 根据品种编号搜索所有需求，并自动进行累计
    /// 选择进入需要创建采购单或生产单队列，
    /// 创建生产单
    /// 创建留位关系
    /// </summary>
    public partial class TRWD02
    { 
        public TRWD02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWDECK();
            DataContext = MV;
            InitializeComponent();
         } 
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                ABAUF = "";
                return;
            } 
            ABAUF = dwMaster["WDAUFKRS"].ToString() + dwMaster["WDAUFLFD"].ToString() + dwMaster["WDAUFPOS"].ToString() + dwMaster["WDUPOS"].ToString() + "VA ";

        }  
        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                dwData = TBMain.Clone().NewRow();
                dwData["WDMANDANT"] = app.Mandant;
                dwData["WDSA"] = WDSA;
                dwData["WDTYP"] = WZTYP;
                dwData["WDWAKZ"] =ARTST;
                dwData["WDART"] = ART.Trim();
                dwData["WDFARBE"] = FARBE.Trim();
                dwData["WDAUFKRS"] = " AND WDAUFKRS LIKE '%" + KRS.Trim() + "%'";
                dwData["WDAUFLFD"] = " AND WDAUFLFD LIKE '%" + LFD.Trim() + "%'";
                dwData["WDAUFPOS"] = " AND WDAUFPOS LIKE '%" + POS.Trim() + "%'"; 
                if(WZTYP=="N")
                {
                    dwData["WDKUNDNR"] = " AND WDZUGET + WDRESERV < WDBEDARF";
                }
                else
                {
                    dwData["WDKUNDNR"] = "";
                }
                dwData["WDBEDST"] = " AND ABPAUFART='" + AUFART + "'";
                SResult = TMV.QWD27(dwData);
                MergeData(SResult, false); 
                base.QueryCommand(sender, e); 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        } 
    }
}
